package ent

import (
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/schema/field"
	"entgo.io/ent/schema/mixin"
)

type OrmMixin struct {
	mixin.Schema
}

func (OrmMixin) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{
			Charset: "utf8mb4",
			Options: "ENGINE = INNODB",
		},
	}
}

func (OrmMixin) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("id").Unique().Immutable(),
		field.Time("created_at").
			Default(time.Now).Immutable(),
		field.Time("updated_at").
			Default(time.Now).UpdateDefault(time.Now),
	}
}
